/** 
 * ================================================================================
 * 		Project		: Kompas Bola
 * 		File		: Constants.java
 * 		Description	: Constant Primitif Type
 * 		Called		: All
 * ================================================================================
 * */
package com.kompas.bola.application.utils;

import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.SharedPreferences;
/** =============================================================================== */
public class Utils {
	/** =========================================================================== */
    public static void CopyStream(InputStream is, OutputStream os)
    {
        final int buffer_size=2024;
        try
        {
            byte[] bytes=new byte[buffer_size];
            for(;;)
            {
              int count=is.read(bytes, 0, buffer_size);
              if(count==-1)
                  break;
              os.write(bytes, 0, count);
            }
        }
        catch(Exception ex){}
    }
	/** =========================================================================== */
    public static String convertDateTimeToFormattedTime(String paramString)
    {
        StringBuilder build 			= new StringBuilder();
        if(!paramString.equalsIgnoreCase(Constants.EMPTY)){
            long now 					= System.currentTimeMillis();
            long date 					= datetimeStringToMilis(paramString);
            long time					= 0L;
            
              if (now > date)
              	time = now - date;
              
              build.append(TimeUtils.milisToTimeMessage(time));
              
              if (build.toString().trim().equals(""))
              	build.append(paramString);
      	  
        }
        return build.toString();
    }
	/** =========================================================================== */
    public static long datetimeStringToMilis(String paramString){
      long date = 0L;
        try {
        	date 					= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", 
        							Locale.US).parse(paramString).getTime();
        	} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return date;
    }
	/** =========================================================================== */
    public static boolean isApplicationSentToBackground(Context paramContext)
    {
      List<RunningTaskInfo> list 	= ((ActivityManager)paramContext.getSystemService("activity"))
    		  						.getRunningTasks(1);
      boolean i;
      if ((list.isEmpty()) || (((ActivityManager.RunningTaskInfo)list.get(0)).topActivity
    		  						.getPackageName().equals(paramContext.getPackageName())))
        i 							= false;
      else
        i 							= true;	
      return i;
    }
	/** =========================================================================== */
    public static int loadDetailZoom(Context paramContext)
    {
      int i 						= 1;
      try
      {
        i 							= paramContext.getSharedPreferences("zoom_persistance", 0).getInt("zoom_persistance", 1);
        return i;
      }
      catch (Exception e)
      {
        while (true)
      	  e.printStackTrace();
      }
    }
	/** =========================================================================== */
    public static void saveDetailZoom(Context paramContext, int paramInt)
    {
      try
      {
        SharedPreferences.Editor editor = paramContext.getSharedPreferences("zoom_persistance", 0).edit();
        editor.putInt("zoom_persistance", paramInt);
        editor.commit();
        return;
      }
      catch (Exception localException)
      {
        while (true)
      	  localException.printStackTrace();
      }
    }
	/** =========================================================================== */
}